package zpx.util;

import zpx.model.DataDictionaryItem;
import zpx.model.DataDictionaryItems;

public class DictionaryUtil {

	public DictionaryUtil() {
	  }
	 

	  /**
	   * 根据数据项名称转换为数据项编码
	   * @param groupName String
	   * @param itemName String
	   * @return String  数据项编码
	   */
	  public static String getItemCode(String groupName, String itemName)
	  {
	    String code = "-1";
	    DataDictionaryItems dataItems = XMLDDItemParser.getDataDictionaryItems(groupName);
	   
	    java.util.ArrayList items = dataItems.getDataDictioanryItems();
	    if(items != null)
	    {
	      DataDictionaryItem item;
	      for(int i = 0; i < items.size(); i++)
	      {
	        item = (DataDictionaryItem) items.get(i);
	        if(item != null)
	        {
	          String name = item.getName();
	          if(name.equals(itemName))
	          {
	            code = item.getCode();
	            break;
	          }
	        }
	      }
	    }
	    return code;
	  }
	  /**
	   * 根据数据项编码转换为数据项名称
	   * @param groupName String
	   * @param itemCode String
	   * @return String
	   */ 
	  public static String getItemName(String groupName, String itemCode)
	  {
	    String name = "未知";
	    DataDictionaryItems dataItems = XMLDDItemParser.getDataDictionaryItems(groupName);
	   
	    java.util.ArrayList items = dataItems.getDataDictioanryItems();
	    if (items != null)
	    {
	      DataDictionaryItem item;
	      for (int i = 0; i < items.size(); i++)
	      {
	        item = (DataDictionaryItem) items.get(i);
	        if (item != null)
	        {
	          String code = item.getCode();
	          if (code.equals(itemCode))
	          {
	            name = item.getName();
	            break;
	          }
	        }
	      }
	    }
	    return name;
	  }
}
